package com.store.practice.controller;

import com.store.practice.common.api.CommonResult;
import com.store.practice.dto.StaffUpdateParam;
import com.store.practice.model.BgStoreStaff;
import com.store.practice.service.BgStoreStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "BeauticianInfoController",description = "美容师信息管理")
@RequestMapping("/beautician")
public class BeauticianInfoController {
    @Autowired
    private BgStoreStaffService storeStaffService;

    @ApiOperation("实名注册")
    @PostMapping("/insert")
    public CommonResult insert(Integer accountId,@RequestParam("tagIds") List<Integer> tagIds, @RequestBody BgStoreStaff staff){
        int i = storeStaffService.insert(accountId, tagIds, staff);
        if (i>0){
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }

    @ApiOperation("通过审核获取APP首页信息")
    @GetMapping("/getApp")
    public CommonResult getApp(Integer accountId){
        Map result = storeStaffService.getApp(accountId);
        if (result==null){
            return CommonResult.failed("用户未实名注册");
        }
        return CommonResult.success(result);
    }

    @ApiOperation("获取个人中心信息")
    @GetMapping("/getStaff")
    public CommonResult getStaff(Integer staffId){
        Map result = storeStaffService.getStaff(staffId);
        return CommonResult.success(result);
    }

    /**
     * 需补充编辑图片参数和实现代码
     * @param staffId
     * @param param
     * @return
     */
    @ApiOperation("编辑个人中心信息")
    @PostMapping("/updateApp")
    public CommonResult updateApp(Integer staffId,String fileUrl,@RequestBody StaffUpdateParam param){
        int i = storeStaffService.updateApp(staffId,fileUrl, param);
        if (i>0){
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }

    @ApiOperation("上传头像")
    @PostMapping("/upload")
    public CommonResult upload(@RequestParam("file")MultipartFile file){
        Map result = storeStaffService.upload(file);
        if (result==null){
            return CommonResult.failed();
        }
        return CommonResult.success(result);
    }

    @ApiOperation("获取个人预约记录")
    @GetMapping("/getOrder")
    public CommonResult getOrder(Integer staffId){
        List<Map> result = storeStaffService.getOrder(staffId);
        if (result==null){
            return CommonResult.failed();
        }
        return CommonResult.success(result);
    }

    @ApiOperation("美容师操作预约状态")
    @PostMapping("/updateStatus")
    public CommonResult updateStatus(Integer orderId,Integer param){
        int i = storeStaffService.updateStatus(orderId, param);
        if (i>0){
            return CommonResult.success(i);
        }
        return CommonResult.failed();
    }
}
